package arithmetic.leetCode.yi;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yilin
 * Date: 2019-07-15
 * Time: 16:59
 */
public class LargestStr {

    public static void main(String[] args) {
        System.out.println(lengthOfLongestSubstring("pwwkew"));
    }

    public static int lengthOfLongestSubstring(String s) {
        int i = 0, j = 0, resMax = 0;
        int strLength = s.length();
        int[] hash = new int[256];
        while (i < strLength && j < strLength) {
            if (hash[s.charAt(j)] == 0) {
                hash[s.charAt(j)] = 1;
                j++;
                resMax = resMax > j - i ? resMax : j - i;
            } else {
                hash[s.charAt(i)] = 0;
                i++;
            }
        }
        return resMax;

    }
}
